package com.bit.net.component.data.server.module.time;

import com.bit.net.Request;
import com.bit.net.RequestContext;
import com.bit.net.Handler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * self-protocal-PingHandler
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/10/11 上午 10:32
 */
@Slf4j
@Component
public class TimeHandler implements Handler {

    @Override
    public void handleRequest(RequestContext requestContext) {
        TimeRequest payload = (TimeRequest) requestContext.getPayload();
        log.info("接收到客户端发送消息【{}】", payload.getMsg());
        requestContext.getChannel().writeAndFlush(new TimeResponse().setTime("time->" + System.currentTimeMillis()));
    }

    @Override
    public Class<? extends Request> getSupported() {
        return TimeRequest.class;
    }

    @Override
    public boolean isSupported(Class<? extends Request> clazz) {
        return clazz.equals(TimeRequest.class);
    }
}
